﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Adex;
using Telerik.Web.UI;
using SubSonic.Sugar;
using System.Security;
using MediaMonitor.Common;
using Ionic.Zip;
using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using System.Drawing;
using OfficeOpenXml.Drawing.Chart;
using Telerik.Charting;
using Telerik.Charting.Styles;
using System.Transactions;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Configuration;
using SubSonic;


namespace MediaMonitor.Users
{
    public partial class AllLastNewsAlertGraph : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["Code"] != "" && Request.QueryString["Code"] != null)
                {
                    bindchart(Request.QueryString["Code"].ToString(), "");
                }
            }
        }
        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        ///        Required method for Designer support - do not modify
        ///        the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.ChartAvenueReport.Click += new Telerik.Web.UI.RadChart.ChartClickEventHandler(this.RadChart1_Click);

        }
        private void RadChart1_Click(object sender, ChartClickEventArgs args)
        {

            bindchart(Request.QueryString["Code"].ToString(), args.SeriesItem.Name);
          
            //this.BindChartResult(this.ViewState["mediaTypeName"].ToString(), args.SeriesItem.Name);
        }
        #endregion
        public void bindchart(string code,string calification)
        {
            DataTable dt = null;
            switch (code)
            {
                case "last":
                    dt = SPs.NewsalertLastCalificacion(Request.Cookies["User"]["Company"].ToString(), Request.QueryString["Code"].ToString(), calification).GetDataSet().Tables[0];
                    break;
                case "pending":
                    dt = SPs.NewsalertPendingCalificacion(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), Request.QueryString["Code"].ToString()).GetDataSet().Tables[0];
                    break;
                case "Today":
                    dt = SPs.NewsalertTodayCalificacion(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), DateTime.Now.ToShortDateString(), Request.QueryString["Code"], calification).GetDataSet().Tables[0];
                    break;
            }
            if (dt.Rows.Count > 0)
            {
                bool flag;
                Color[] green = new Color[] { Color.Green, Color.Red, Color.Blue };
                Color[] barColors = green;
                //DataTable dt = SPs.NewsalertLastCalificacion(Request.Cookies["User"]["Company"].ToString(), Request.QueryString["Code"].ToString()).GetDataSet().Tables[0];
                ChartAvenueReport.DataSource = dt;
                ChartAvenueReport.DataBind();
                flag = (!(dt.Rows[0][1].ToString() == "0") || !(dt.Rows[1][1].ToString() == "0") ? true : !(dt.Rows[2][1].ToString() == "0"));
                bool flag1 = flag;
                if (!flag1)
                {
                    this.ChartAvenueReport.Visible = false;
                }
                this.ChartAvenueReport.PlotArea.XAxis.AxisLabel.Visible = false;
                int i = 0;
                this.ChartAvenueReport.PlotArea.XAxis.AutoScale = false;
                this.ChartAvenueReport.PlotArea.XAxis.AddRange(1, 3, 1);
                IEnumerator<ChartSeriesItem> enumerator = this.ChartAvenueReport.Series[0].Items.GetEnumerator();
                try
                {
                    while (true)
                    {
                        flag1 = enumerator.MoveNext();
                        if (!flag1)
                        {
                            break;
                        }
                        ChartSeriesItem item = enumerator.Current;
                        int num = i;
                        i = num + 1;
                        item.Appearance.FillStyle.MainColor = barColors[num];
                    }
                }
                finally
                {
                    flag1 = enumerator == null;
                    if (!flag1)
                    {
                        enumerator.Dispose();
                    }
                }
                this.ChartAvenueReport.PlotArea.XAxis[0].TextBlock.Text = dt.Rows[0][1].ToString();
                this.ChartAvenueReport.PlotArea.XAxis[1].TextBlock.Text = dt.Rows[1][1].ToString();
                this.ChartAvenueReport.PlotArea.XAxis[2].TextBlock.Text = dt.Rows[2][1].ToString();
                this.ChartAvenueReport.Skin = " DeepGreen";
            }
            else
            {
                ChartAvenueReport.Visible = false;
            }
        }
    }
}